
**********************************
**age and prior exposure effects**
**********************************

clear
cd "/Users/u6026357/Desktop/Age/"
set scheme s1mono

************************************
**descriptives at respondent lvl****
************************************

clear
use "June.dta" 
sum accuracy_fake_mean accuracy_real_mean accuracy_fake_meanw2 accuracy_real_meanw2 mean_acc_diffw2 mean_acc_diff
sum accuracy_hyper_meanw2 accuracy_hyper_mean
clear
use "oct-pulse.dta" 
sum accuracy_fake_mean accuracy_real_mean accuracy_fake_meanw2 accuracy_real_meanw2 mean_acc_diffw2 mean_acc_diff
sum accuracy_hyper_meanw2 accuracy_hyper_mean
clear
use "post-pulse.dta" 
sum accuracy_fake_mean accuracy_real_mean accuracy_fake_meanw2 accuracy_real_meanw2 mean_acc_diffw2 mean_acc_diff
sum accuracy_hyper_meanw2 accuracy_hyper_mean

**pool respondent level data**
clear
use "June.dta" 
append using "oct-pulse.dta"  "post-pulse.dta", force gen(newvar_resp)

sum accuracy_fake_mean accuracy_real_meanw2 accuracy_hyper_meanw2 if agecat ==1
sum accuracy_fake_mean accuracy_real_meanw2 accuracy_hyper_meanw2 if agecat ==2
sum accuracy_fake_mean accuracy_real_meanw2 accuracy_hyper_meanw2 if agecat ==3
sum accuracy_fake_mean accuracy_real_meanw2 accuracy_hyper_meanw2 if agecat ==4

sum accuracy_fake_meanw2 accuracy_real_meanw2 accuracy_hyper_meanw2 if agecat ==1
sum accuracy_fake_meanw2 accuracy_real_meanw2 accuracy_hyper_meanw2 if agecat ==2
sum accuracy_fake_meanw2 accuracy_real_meanw2 accuracy_hyper_meanw2 if agecat ==3
sum accuracy_fake_meanw2 accuracy_real_meanw2 accuracy_hyper_meanw2 if agecat ==4

corr accuracy_fake_mean age
corr accuracy_real_mean age
corr accuracy_fake_meanw2 age
corr accuracy_real_meanw2 age

******************************
**pool wave 2 headline data***
******************************
clear
use "junew2.dta"

**need new congenial var for June
gen pro_d=(dv==8 | dv==6 | dv==5 | dv==7 | dv==1 | dv==2 | dv==15 | dv==16)
gen pro_r=(dv==10 | dv==12 | dv==11 | dv==9 | dv==3 | dv==4 | dv==13 | dv==14)
gen congenial=(pro_d==1 & dem_leaner==1) | (pro_r==1 & repub_leaner==1)
gen uncongenial=(pro_r==1 & dem_leaner==1) | (pro_d==1 & repub_leaner==1)

**need new saw var for June
foreach var of varlist accuracy_trumpsister accuracy_michgop accuracy_millionsrush accuracy_dickdurbin accuracy_trumpangry accuracy_whofficial accuracy_trumpforeign accuracy_whsecurity accuracy_repubsvote accuracy_goplawmaker accuracy_demrunning accuracy_demsworry accuracy_worldfeels accuracy_twoyearstudy accuracy_mueller accuracy_ndcongress {
gen saw_`var'=(`var'!=.)
}

gen saw=0
replace saw=1 if (dv==1 & saw_accuracy_trumpsister==1) | (dv==2 & saw_accuracy_michgop==1) | (dv==3 & saw_accuracy_millions==1) | (dv==4 & saw_accuracy_dickdurb==1) | (dv==5 & saw_accuracy_trumpang==1) | (dv==6 & saw_accuracy_whoffic==1) | (dv==7 & saw_accuracy_trumpf==1) | (dv==8 & saw_accuracy_whsec==1) | (dv==9 & saw_accuracy_repubsvote==1) | (dv==10 & saw_accuracy_goplaw==1) | (dv==11 & saw_accuracy_demrun==1) | (dv==12 & saw_accuracy_demsw==1) | (dv==13 & saw_accuracy_worldf==1) | (dv==14 & saw_accuracy_twoy==1) | (dv==15 & saw_accuracy_muell==1) | (dv==16 & saw_accuracy_ndc==1)

recode dv 1=17 2=18 3=19 4=20 5=21 6=22 7=23 8=24 9=25 10=26 11=27 12=28 13=29 14=30 15=31 16=32

append using "oct-headlinew2.dta" "for-jacob-US-headlinelevelw2.dta",  gen(newvarw2)

**************************
**************************
**prior exposure analysis*
**************************
**************************

drop saw_age
gen saw_age = saw*age

**main effects**
reg accuracyw2 congenial  saw ib1.agecat i.dv , robust cluster(caseid)
est store prior_age_overall_npim
reg accuracyw2 congenial saw ib1.agecat  i.dv if fake==1, robust cluster(caseid)
est store prior_age_fake_npim
reg accuracyw2 congenial saw ib1.agecat  i.dv  if hyper==1, robust cluster(caseid)
est store prior_age_hyper_npim
reg accuracyw2 congenial saw ib1.agecat  i.dv  if real==1, robust cluster(caseid)
est store prior_age_real_npim

**main effects table
estout prior_age_overall_npim prior_age_fake_npim prior_age_hyper_npim prior_age_real_npim using prior_main.tex,replace varwidth(25) collabels("") cells(b(star fmt(%9.4f)) se(par fmt(%9.4f))) stats(r2 N, fmt(%9.2f %9.0f) labels("R^2" "N")) starlevels(* 0.05 ** 0.01 *** 0.005) style(tex) 

**main effects coefplot
reg accuracyw2 congenial  saw  agecat2 agecat3 agecat4 i.dv , robust cluster(caseid)
est store prior_age_overall_npimx
reg accuracyw2 congenial saw  agecat2 agecat3 agecat4  i.dv if fake==1, robust cluster(caseid)
est store prior_age_fake_npimx
reg accuracyw2 congenial saw  agecat2 agecat3 agecat4  i.dv  if hyper==1, robust cluster(caseid)
est store prior_age_hyper_npimx
reg accuracyw2 congenial saw  agecat2 agecat3 agecat4  i.dv  if real==1, robust cluster(caseid)
est store prior_age_real_npimx

coefplot prior_age_overall_npimx, keep(agecat1 agecat2 agecat3 agecat4 saw) title("Pooled") xlabel(-.3 "-.3" -.2 "-.2" -.1 "-.1" 0 "0" .1 ".1" .2 ".2" ) xline(0)  aspect(1) grid( glcolor(none)) 
graph save main_pool.gph, replace
coefplot prior_age_real_npimx, keep(agecat1 agecat2 agecat3 agecat4 saw) title("Mainstream") xlabel(-.3 "-.3" -.2 "-.2" -.1 "-.1" 0 "0" .1 ".1" .2 ".2" ) xline(0) aspect(1) grid( glcolor(none)) 
graph save main_real.gph, replace
coefplot prior_age_hyper_npimx, keep(agecat1 agecat2 agecat3 agecat4 saw) title("Hyperpartisan") xlabel(-.3 "-.3" -.2 "-.2" -.1 "-.1" 0 "0" .1 ".1" .2 ".2" ) xline(0) aspect(1) grid( glcolor(none)) 
graph save main_hyper.gph, replace
coefplot prior_age_fake_npimx, keep(agecat1 agecat2 agecat3 agecat4 saw) title("False") xlabel(-.3 "-.3" -.2 "-.2" -.1 "-.1" 0 "0" .1 ".1" .2 ".2" ) xline(0) aspect(1) grid( glcolor(none)) 
graph save main_fake.gph, replace
grc1leg2  main_real.gph main_hyper.gph main_fake.gph, cols(3)
gr save main_coef.gph, replace
gr export "main_coef.pdf", replace

**linear**
reg accuracyw2 congenial  saw age saw_age i.dv , robust cluster(caseid)
est store prior_age_overall_np
reg accuracyw2 congenial i.saw c.age saw_age i.dv if fake==1, robust cluster(caseid)
est store prior_age_fake_np
reg accuracyw2 congenial saw age saw_age i.dv  if hyper==1, robust cluster(caseid)
est store prior_age_hyper_np
reg accuracyw2 congenial saw age saw_age i.dv  if real==1, robust cluster(caseid)
est store prior_age_real_np

**agecat**
reg accuracyw2 congenial  saw##ib1.agecat i.dv , robust cluster(caseid)
est store prior_age_overall_npi
qui margins saw, at(agecat=(1(1)4))
marginsplot, title("Pooled") xtitle("") ytitle("Perceived Accuracy") ylabel(1.75 "1.75" 2.25 "2.25" 2.75 "2.75") aspect(1.5)
graph save "all", replace

reg accuracyw2 congenial i.saw##agecat  i.dv if fake==1, robust cluster(caseid)
est store prior_age_fake_npi
qui margins saw, at(agecat=(1(1)4))
marginsplot , title("False") xtitle("") ytitle("Perceived Accuracy") ylabel(1.75 "1.75" 2.25 "2.25" 2.75 "2.75") aspect(1.5)
graph save "fake", replace

reg accuracyw2 congenial saw##ib1.agecat  i.dv  if real==1, robust cluster(caseid)
est store prior_age_real_npi
qui margins saw, at(agecat=(1(1)4))
marginsplot , title("Mainstream") xtitle("") ytitle("Perceived Accuracy") ylabel(1.75 "1.75" 2.25 "2.25" 2.75 "2.75") aspect(1.5)
graph save "real", replace

reg accuracyw2 congenial saw##ib1.agecat  i.dv  if hyper==1, robust cluster(caseid)
est store prior_age_hyper_npi
qui margins saw, at(agecat=(1(1)4))
marginsplot , title("Hyperpartisan") xtitle("") ytitle("Perceived Accuracy") ylabel(1.75 "1.75" 2.25 "2.25" 2.75 "2.75") aspect(1.5)
graph save "hyper", replace

**marginsplot
grc1leg2  real.gph hyper.gph fake.gph, cols(3)
graph save margins_3.gph, replace
graph export "margins_3.pdf", replace

**coefplot 
reg accuracyw2 congenial saw i.dv  if fake==1|agecat==1, robust cluster(caseid)
est store prior_age_fake_npi_a1
reg accuracyw2 congenial saw i.dv if fake==1|agecat==2, robust cluster(caseid)
est store prior_age_fake_npi_a2
reg accuracyw2 congenial saw i.dv  if fake==1|agecat==3, robust cluster(caseid)
est store prior_age_fake_npi_a3
reg accuracyw2 congenial saw i.dv if fake==1|agecat==4, robust cluster(caseid)
est store prior_age_fake_npi_a4
coefplot prior_age_fake_npi_a1 prior_age_fake_npi_a2 prior_age_fake_npi_a3 prior_age_fake_npi_a4, keep(saw) xlabel(-.1 "-.1" 0 "0" .1 ".1" .2 ".2") xline(0)
graph save fake_coef.gph, replace

reg accuracyw2 congenial saw i.dv  if real==1|agecat==1, robust cluster(caseid)
est store prior_age_real_npi_a1
reg accuracyw2 congenial saw i.dv if real==1|agecat==2, robust cluster(caseid)
est store prior_age_real_npi_a2
reg accuracyw2 congenial saw i.dv  if real==1|agecat==3, robust cluster(caseid)
est store prior_age_real_npi_a3
reg accuracyw2 congenial saw i.dv if real==1|agecat==4, robust cluster(caseid)
est store prior_age_real_npi_a4
coefplot prior_age_real_npi_a1 prior_age_real_npi_a2 prior_age_real_npi_a3 prior_age_real_npi_a4, keep(saw) xlabel(-.1 "-.1" 0 "0" .1 ".1" .2 ".2")  xline(0)
graph save real_coef.gph, replace

grc1leg2  real_coef.gph fake_coef.gph, cols(2)
graph save coef.gph, replace
graph export "coef.pdf", replace

**tables
**agecat pooled
estout prior_age_overall_npi using age_prior_pool.tex, replace varwidth(25) collabels("") cells(b(star fmt(%9.4f)) se(par fmt(%9.4f))) stats(r2 N, fmt(%9.2f %9.0f) labels("R^2" "N")) starlevels(* 0.05 ** 0.01 *** 0.005) style(tex) 

**agecat by type
estout prior_age_fake_npi prior_age_hyper_npi prior_age_real_npi using age_prior_type.tex, replace varwidth(25) collabels("") cells(b(star fmt(%9.4f)) se(par fmt(%9.4f))) stats(r2 N, fmt(%9.2f %9.0f) labels("R^2" "N")) starlevels(* 0.05 ** 0.01 *** 0.005) style(tex) 

**linear
estout prior_age_overall_np prior_age_fake_np prior_age_hyper_np prior_age_real_np using age_prior_linear.tex, replace varwidth(25) collabels("") cells(b(star fmt(%9.4f)) se(par fmt(%9.4f))) stats(r2 N, fmt(%9.2f %9.0f) labels("R^2" "N")) starlevels(* 0.05 ** 0.01 *** 0.005) style(tex) 

*******************************
**supplemental analysis********
*******************************

**with controls**
**linear**
reg accuracyw2 congenial  saw age saw_age dem_leaners repub_leaners polknow polint college female nonwhite i.dv , robust cluster(caseid)
est store prior_age_overall_npc
reg accuracyw2 congenial saw age saw_age dem_leaners repub_leaners polknow polint college female nonwhite i.dv if fake==1, robust cluster(caseid)
est store prior_age_fake_npc
reg accuracyw2 congenial saw age saw_age dem_leaners repub_leaners polknow polint college female nonwhite i.dv  if hyper==1, robust cluster(caseid)
est store prior_age_hyper_npc
reg accuracyw2 congenial saw age saw_age dem_leaners repub_leaners polknow polint college female nonwhite i.dv  if real==1, robust cluster(caseid)
est store prior_age_real_npc
**agecat**
reg accuracyw2 congenial  saw##ib1.agecat dem_leaners repub_leaners polknow polint college female nonwhite i.dv , robust cluster(caseid)
est store prior_age_overall_npic
reg accuracyw2 congenial saw##ib1.agecat dem_leaners repub_leaners polknow polint college female nonwhite  i.dv if fake==1, robust cluster(caseid)
est store prior_age_fake_npic
reg accuracyw2 congenial saw##ib1.agecat dem_leaners repub_leaners polknow polint college female nonwhite  i.dv  if hyper==1, robust cluster(caseid)
est store prior_age_hyper_npic
reg accuracyw2 congenial saw##ib1.agecat dem_leaners repub_leaners polknow polint college female nonwhite  i.dv  if real==1, robust cluster(caseid)
est store prior_age_real_npic

**tables with controls 
**agecat 
estout prior_age_overall_npic prior_age_fake_npic prior_age_hyper_npic prior_age_real_npic using age_prior_typec.tex, replace varwidth(25) collabels("") cells(b(star fmt(%9.4f)) se(par fmt(%9.4f))) stats(r2 N, fmt(%9.2f %9.0f) labels("R^2" "N")) starlevels(* 0.05 ** 0.01 *** 0.005) style(tex) 
**linear
estout prior_age_overall_npc prior_age_fake_npc prior_age_hyper_npc prior_age_real_npc using age_prior_linearc.tex, replace varwidth(25) collabels("") cells(b(star fmt(%9.4f)) se(par fmt(%9.4f))) stats(r2 N, fmt(%9.2f %9.0f) labels("R^2" "N")) starlevels(* 0.05 ** 0.01 *** 0.005) style(tex) 

**using alternate age groups
gen agecatx=age
/* -age groups (18-29, 30-44, 45-59, 60-64, 65+*/
replace agecatx=1 if age>17
replace agecatx=2 if age>29
replace agecatx=3 if age>44
replace agecatx=4 if age>59
replace agecatx=5 if age>64
replace agecatx=. if age==.

**alt models 65+
**agecat**
reg accuracyw2 congenial  saw##ib1.agecatx i.dv , robust cluster(caseid)
est store prior_age_overall_npi2
reg accuracyw2 congenial saw##ib1.agecatx  i.dv if fake==1, robust cluster(caseid)
est store prior_age_fake_npi2
reg accuracyw2 congenial saw##ib1.agecatx  i.dv  if hyper==1, robust cluster(caseid)
est store prior_age_hyper_npi2
reg accuracyw2 congenial saw##ib1.agecatx  i.dv  if real==1, robust cluster(caseid)
est store prior_age_real_npi2

**age x prior x congenial exploratory analysis
gen saw_c = saw*congenial
gen age_c = age*congenial
gen age_saw_c = age*congenial*saw

**first, show prior x congenial increases 
reg accuracyw2 congenial saw agecat  saw_c  i.dv, robust cluster(caseid)
reg accuracyw2 congenial saw agecat  saw_c  i.dv if fake==1, robust cluster(caseid)
reg accuracyw2 congenial saw agecat  saw_c   i.dv if hyper==1, robust cluster(caseid)
reg accuracyw2 congenial saw agecat  saw_c   i.dv if real==1, robust cluster(caseid)

**now show age x congenial increases 
reg accuracyw2 congenial saw agecat  saw_c age_c  i.dv, robust cluster(caseid)
reg accuracyw2 congenial saw agecat  saw_c age_c  i.dv if fake==1, robust cluster(caseid)
reg accuracyw2 congenial saw agecat  saw_c age_c  i.dv if hyper==1, robust cluster(caseid)
reg accuracyw2 congenial saw agecat  saw_c age_c  i.dv if real==1, robust cluster(caseid)

**now three way 
reg accuracyw2 congenial saw agecat saw_age saw_c age_c age_saw_c i.dv, robust cluster(caseid)
est store prior_age_overall_npc
reg accuracyw2 congenial saw agecat saw_age saw_c age_c age_saw_c i.dv if fake==1, robust cluster(caseid)
est store prior_age_fake_npc
reg accuracyw2 congenial saw agecat saw_age saw_c age_c age_saw_c i.dv if hyper==1, robust cluster(caseid)
est store prior_age_hyper_npc
reg accuracyw2 congenial saw agecat saw_age saw_c age_c age_saw_c i.dv if real==1, robust cluster(caseid)
est store prior_age_real_npc

**now subset by congenial 
**agecat
reg accuracyw2  saw##ib1.agecat   i.dv if congenial==1, robust cluster(caseid)
est store pool_cong
reg accuracyw2  saw##ib1.agecat   i.dv if congenial==0, robust cluster(caseid)
est store pool_un
reg accuracyw2  saw##ib1.agecat   i.dv if fake==1|congenial==1, robust cluster(caseid)
est store fake_cong
reg accuracyw2  saw##ib1.agecat   i.dv if fake==1|congenial==0, robust cluster(caseid)
est store fake_un
reg accuracyw2  saw##ib1.agecat   i.dv if hyper==1|congenial==1, robust cluster(caseid)
est store hyper_cong
reg accuracyw2  saw##ib1.agecat   i.dv if hyper==1|congenial==0, robust cluster(caseid)
est store hyper_un
reg accuracyw2  saw##ib1.agecat   i.dv if real==1|congenial==1, robust cluster(caseid)
est store real_cong
reg accuracyw2  saw##ib1.agecat   i.dv if real==1|congenial==0, robust cluster(caseid)
est store real_un

**linear
reg accuracyw2  saw agecat saw_age  i.dv if congenial==1, robust cluster(caseid)
est store pool_congl
reg accuracyw2  saw agecat saw_age  i.dv if congenial==0, robust cluster(caseid)
est store pool_unl
reg accuracyw2  saw agecat saw_age  i.dv if fake==1|congenial==1, robust cluster(caseid)
est store fake_congl
reg accuracyw2  saw agecat saw_age  i.dv if fake==1|congenial==0, robust cluster(caseid)
est store fake_unl
reg accuracyw2  saw agecat saw_age  i.dv if hyper==1|congenial==1, robust cluster(caseid)
est store hyper_congl
reg accuracyw2  saw agecat saw_age  i.dv if hyper==1|congenial==0, robust cluster(caseid)
est store hyper_unl
reg accuracyw2  saw agecat saw_age  i.dv if real==1|congenial==1, robust cluster(caseid)
est store real_congl
reg accuracyw2  saw agecat saw_age  i.dv if real==1|congenial==0, robust cluster(caseid)
est store real_unl

**subset table
estout pool_cong pool_un fake_cong fake_un hyper_cong hyper_un real_cong real_un using age_subset.tex, replace varwidth(25) collabels("") cells(b(star fmt(%9.4f)) se(par fmt(%9.4f))) stats(r2 N, fmt(%9.2f %9.0f) labels("R^2" "N")) starlevels(* 0.05 ** 0.01 *** 0.005) style(tex) 

**congeniality margins 
reg accuracyw2 i.congenial i.saw##agecat  i.dv if fake==1, robust cluster(caseid)
est store cong_fake
margins i.congenial // .27 + .28 = .55/4 = 14%

reg accuracyw2 i.congenial i.saw##agecat  i.dv if fake==1, robust cluster(caseid)
est store cong_fake
margins i.congenial, at(agecat==4) //32 + 22 = .54/4 = 13.5%
 


